package XML;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Creaza fisierul si stream-ul corespunzator scrierii acestuia
 * @author AlinT
 */

public class XMLPrinter {

	private static FileWriter fstream= null;
	private static BufferedWriter writer= null;

        /**
         * Functia ce adauga un tag fisierului XML
         * @param s tagul primit
         */
	public void write(String s)
	{
		try {
			writer.append(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

        /**
         * Constructor ce creaza fisierul "Copac.XML" si stream-ul de scriere
         */
	public XMLPrinter()
	{

		try {
			fstream=new FileWriter(DocumentXML.getInstance().getXMLFile());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		writer= new BufferedWriter(fstream);
		try {
			writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
			writer.write("\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
        
	public static BufferedWriter getWriter() {
		return writer;
	}
}
